<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ShopCategory extends Model
{
    use HasFactory;
    protected $table = 'sp_shop_category';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //商户分类状态
    const SHOP_CATEGORY_STATUS_ENABLE = 1;//启用
    const SHOP_CATEGORY_STATUS_DISABLE = 2;//禁用

    //商户分类是否删除
    const SHOP_CATEGORY_DELETE_YES = 1;//已删除
    const SHOP_CATEGORY_DELETE_NO = 0;//未删除

    //店铺分类列表
    protected function GetShopCategoryList($pageSize, $where)
    {
        $select = array('id', 'member_id', 'sort', 'cat_name', 'create_time');
        $data = $this
            ->select($select)
            ->where($where)
            ->orderBy('sort', 'asc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //根据id查询
    protected function GetShopCategoryById($id)
    {
        $where = array(
            'id' => $id,
        );
        $data = $this
            ->where($where)
            ->first();
        $data = $data ? $data->toArray() : [];
        return $data;
    }

    //添加
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }

    //根据id修改
    protected function editDataById($id, $data)
    {
        $where = array(
            'id' => $id,
        );
        return $data = $this->where($where)->update($data);
    }

}
